package com.example.homework_05;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class Fragment2 extends Fragment {

    private Button bilbil ;
    private Button baidu ;
    private Button wyy ;
    private View view ;

    public Fragment2() {
        super(R.layout.layout02);
        view = getView() ;
    }

    @Override
    public void onViewCreated(View view,@Nullable Bundle savedInstanceState) {
        super.onViewCreated(view,savedInstanceState);

        bilbil = (Button) getView().findViewById(R.id.bilbil) ;
        baidu = (Button) view.findViewById(R.id.baidu) ;
        wyy = (Button) view.findViewById(R.id.wyy) ;

        baidu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent() ;
                intent.setAction("android.intent.action.VIEW") ;
                intent.setData(Uri.parse("http://www.baidu.com")) ;
                startActivity(intent);
                Log.e("MainActivity","start baidu") ;
            }
        });

        wyy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =getActivity().getPackageManager().getLaunchIntentForPackage("com.netease.cloudmusic");
                startActivity(intent);
                Log.e("MainActivity","start wyy") ;
            }
        });

        bilbil.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage("tv.danmaku.bili");
                startActivity(intent);
                Log.e("MainActivity","start bilbil") ;
            }
        });
    }


}
